{extend name="base" /}

{block name="title"} 节点列表 {/block}


{block name="body"}
<div class="col-lg-12">

    <section class="panel">
        <header class="panel-heading">  
            <span class="mg-r-md">
                条件筛选
            </span>
            <small class="pull-right">
                <a class="fa fa-chevron-down panel-collapsible pd-r-xs" href="javascript:;"></a>
            </small>
        </header>
        <div class="panel-body">
            <form class="form-inline form-search" role="form">

                <div class="form-group mg-t-xs">
                    <label>名称</label>
                    <input type="text" class="form-control" name="name" placeholder="名称">
                </div>

                <div class="form-group col-xs-12 col-md-12 mg-t-xs">
                    <button type="button" class="btn btn-success btn-sm col-xs-12 col-sm-2 col-md-1" onclick="Table.methods.refresh()">搜索</button>
                </div>

            </form>
        </div>

    </section>

    <section class="panel">
        <header class="panel-heading">列表</header>
        <div class="panel-body">
            <div class="table-responsive">
                <table class="table table-hover table-striped no-margin" id="table"> </table>
            </div>
        </div>
    </section>


</div>

{/block}

<!-- js -->
{block name="js"}
<script>

// 操作 
    Table.formatter.operate = function(value, row, index){
        if( row.level >1 ){
            return '<button class="btn btn-xs btn-success" type="button" onclick="Table.methods.edit('+row.id+')"> <i class="fa fa-edit"></i> <span class="hidden-xs hidden-sm">编辑</span></button>   <button class="btn btn-xs btn-info" type="button" disabled="disabled"> <i class="fa fa-code-fork"></i><span class="hidden-xs hidden-sm">新增下级</span></button> <button class="btn btn-xs btn-danger" type="button" onclick="Table.methods.del('+row.id+')">  <i class="fa fa-trash"></i><span class="hidden-xs hidden-sm">删除</span> </button> ';
        }else{
            return '<button class="btn btn-xs btn-success" type="button" onclick="Table.methods.edit('+row.id+')"> <i class="fa fa-edit"></i> <span class="hidden-xs hidden-sm">编辑</span></button>   <button class="btn btn-xs btn-info" type="button" onclick="add_child('+row.id+')"> <i class="fa fa-code-fork"></i><span class="hidden-xs hidden-sm">新增下级</span></button> <button class="btn btn-xs btn-danger" type="button" onclick="Table.methods.del('+row.id+')">  <i class="fa fa-trash"></i><span class="hidden-xs hidden-sm">删除</span> </button> ';
        }
    }

    Table.formatter.name = function(value, row, index){
        var str = '';
        if(row.level > 0){
            str += '|';
        }
        return str+repeat('—',row.level)+value;
    }

    table_config.pagination = false;

    table_config.columns = [
        {
            checkbox: true,  
            visible: true,
            printIgnore: true,
            class: "hidden-xs"
        }, 
        {
            field: 'id',
            title: 'ID',
            titleTooltip: 'ID',
            printIgnore: true
        }, 
        {
            field: 'parent.name',
            title: '上级',
            class: "hidden-xs"
        },
        {
            field: 'name',
            title: '名称',
            titleTooltip: '名称',
            formatter: Table.formatter.name,
            printFormatter: Table.formatter.name,
        },
        {
            field: 'ico',
            title: '图标',
            formatter: Table.formatter.icon,
            printFormatter: Table.formatter.icon,
            class: "hidden-xs"
        }, 
        {
            field: 'controller',
            title: '控制器'
        },
        {
            field: 'action',
            title: '方法'
        },      
        {
            field: 'create_time',
            title: '添加时间',
            formatter: Table.formatter.time,
            printFormatter: Table.formatter.time,
            class: "hidden-xs hidden-sm"
        },
        {
            title: '操作',
            formatter: Table.formatter.operate,
            printIgnore: true
        }
     ];

    // 导出表格名称
    table_config.exportOptions.tableName = table_config.exportOptions.fileName = "节点列表";

    // 忽略导出列
    table_config.exportOptions.ignoreColumn = [0,-1];

    Table.table = $('#table').bootstrapTable(table_config);

    // 新增下级
    function add_child(id) {
        $.get("{:url('create')}?pid="+id, function(data) {
            layer.open({
                type: 1,
            　　title: "新增下级",
            　　shadeClose: true,
            　　shade: 0.4,
                anim: 5,
            　　content: data
            });
        });
    }


</script>
{/block}